package genetics;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class GridIO
{

    public static boolean saveIndividual(Individual ind)
    {
        try {
            FileOutputStream saveFile = new FileOutputStream("bestIndividual.dat");
            ObjectOutputStream save = new ObjectOutputStream(saveFile);

            save.writeObject(ind);

            save.close();
        } catch (Exception e) {
            return false;
        }

        return true;
    }

    public static Individual loadIndividual()
    {
        Individual ind = null;

        try {
            FileInputStream saveFile = new FileInputStream("bestIndividual.dat");
            ObjectInputStream save = new ObjectInputStream(saveFile);

            ind = (Individual) save.readObject();

            save.close();
        } catch (Exception e) {
            return null;
        }

        return ind;
    }
}
